# 计科1915班 0306224505 屠玉宝


class AddressList:
    def __init__(self, dct):
        self.dct = dct

    # tips
    def tips(self):
        print("1: 查询联系人")
        print("2: 插入联系人")
        print("3: 删除联系人")
        print("4: 输出所有联系人")
        print("5: 退出")

    # 查询
    def query(self):
        name = input("请输入联系人姓名：")
        number = self.dct.get(name)
        if number:
            print(f"{name}: {number}")
        else:
            print("您输入的姓名不在通讯录中！")

    # 查询所有
    def get_all(self):
        for k, v in self.dct.items():
            print(f"{k}: {v}")

    # 插入
    def insert(self):
        name = input("请输入联系人姓名：")
        number = input("请输入用户联系电话：")
        # dct.update({name: number})
        self.dct[name] = number
        print(f"插入'{name}'成功")

    # 删除
    def delete(self):
        name = input("请输入联系人姓名：")
        del self.dct[name]
        print("删除成功")

    def run(self):
        self.tips()
        while 1:
            try:
                num = int(input("请入指令: "))
                if num < 1 or num > 5:
                    print("指令不存在")
            except Exception as e:
                print("指令不存在")

            if num == 5:
                exit()
            elif num == 1:
                self.query()
            elif num == 2:
                self.insert()
            elif num == 3:
                self.delete()
            elif num == 4:
                self.get_all()


if __name__ == '__main__':
    d = {"小明": 12345}
    address = AddressList(d)
    address.run()
